<?php 
require_once 'DBUtil.class.php';
require_once 'Reply.class.php';
class ReplyAction {
	//添加
	function add($reply) {
		$con = DBUtil::getCon();
		$sql = "INSERT INTO reply (msg_id, admin_id, content, create_time) VALUES ({$reply->msg_id}, {$reply->admin_id}, '" . addslashes($reply -> content) . "',now())";
		if (!mysql_query($sql)) {
			die('Error: ' . mysql_error());
		} else {
			return mysql_insert_id();
		}
	}
	
	//根据ID查询
	function queryById($reply) {
		$con = DBUtil::getCon();
		$sql = "SELECT * FROM reply WHERE id=" . $reply -> id;
		$result = mysql_query($sql);
		$row = mysql_fetch_array($result);
		$reply -> id = $row['id'];
		$reply -> msg_id = $row['msg_id'];
		$reply -> admin_id = $row['admin_id'];
		$reply -> content = $row['content'];
		$reply -> create_time = $row['create_time'];
		return $reply;
	}
	
	//根据留言ID查询
	function queryByMsgId($msg) {
		$con = DBUtil::getCon();
		$sql = "SELECT * FROM reply WHERE msg_id=" . $msg -> id;
		$result = mysql_query($sql);
		if(mysql_num_rows($result) != 0){
			$row = mysql_fetch_array($result);
			$reply = new Reply();
			$reply -> id = $row['id'];
			$reply -> msg_id = $row['msg_id'];
			$reply -> admin_id = $row['admin_id'];
			$reply -> content = $row['content'];
			$reply -> create_time = $row['create_time'];
			return $reply;
		}else{
			return false;
		}
	}
	//根据留言ID删除
	function delete($msg) {
		$con = DBUtil::getCon();
		$sql = "DELETE FROM reply WHERE msg_id=" . $msg -> id;
		if (!mysql_query($sql)) {
			die('Error: ' . mysql_error());
		} else {
			return true;
		}
	}
}
 ?>